package com.rpj.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.rpj.entity.StuEntity;
import com.rpj.entity.TeaEntity;
import com.rpj.entity.UserEntity;
import com.rpj.service.StuService;
import com.rpj.service.TeaService;
import com.rpj.service.UserService;

@RestController
public class UserController {
	@Autowired
	private UserService userservice;
	@Autowired
	private StuService stuservice;
	@Autowired
	private TeaService teaservice;

	@RequestMapping(value = "/userquery", method = RequestMethod.POST)
	public Object userquery(String username, String userpassword, String select, HttpServletResponse response) {
		/*
		 * if(select.equals("学生")) { stuservice.stulogin(username, userpassword); return
		 * true; }else { return false; } if(select.equals("教师")) {
		 * teaservice.tealogin(username, userpassword); try {
		 * response.sendRedirect("/X-admin/tealogin.html"); } catch (IOException e) { //
		 * TODO Auto-generated catch block e.printStackTrace(); } }else { try {
		 * response.sendRedirect("/X-admin/login.html"); } catch (IOException e) { //
		 * TODO Auto-generated catch block e.printStackTrace(); } }
		 */
		if(select.equals("管理员")) {
		List<UserEntity> query = userservice.query(username, userpassword);
		if(query.size()>0) {
			System.out.println(query);
			return "管理员";
		}else {
			return false;
		}	
		
	}
		if(select.equals("教师")) {
			 TeaEntity tealogin = teaservice.tealogin(username, userpassword);
			if(tealogin!=null) {
				return "教师";
			}else {
				return false;
			}	
			
		}
		if(select.equals("学生")) {
			StuEntity stulogin = stuservice.stulogin(username, userpassword);
			if(stulogin!=null) {
				return "学生";
			}else {
				return false;
			}	
			
		}
		return false;
	}
}
